package com.andy.stripes.actions;

import java.io.StringReader;
import java.util.List;

import com.andy.stripes.domain.Login;
import com.andy.stripes.service.LoginService;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;

import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;


public class LoginActionBean implements ActionBean {

	private static final String VIEW_LIST = "/WEB-INF/jsp/login/view_list.jsp";
	private static final String View_TEST="/WEB-INF/jsp/blog/aretic.html";
	private static final String VIEW_INDEX="/index.jsp";
	private static final String  VIEW_MAIN="/main.jsp";
	private ActionBeanContext context;

	private List<Login> loginList;
	
	private Login login=new Login();

	
	@SpringBean
	private LoginService loginService;

	
	
	public Login getLogin() {
		return login;
	}

	public void setLogin(Login login) {
		this.login = login;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	public ActionBeanContext getContext() {

		return context;

	}

	public void setContext(ActionBeanContext context) {

		this.context = context;

	}

	/**
	 * json
	 */

	public Resolution addition() {

		Login login = loginService.getLogin("111");

		System.out.println("login:" + login.getTestname());

		return new StreamingResolution("text/html", new StringReader(
				"{success:true}"));

	}

	 @DefaultHandler
	public  Resolution  loginInfo()
	{
		
		System.out.println("userName:"+login.getUserName());
		System.out.println("userName:"+login.getUserPass());
		return new ForwardResolution(VIEW_MAIN);
		
	}
	
	
	
   
	public Resolution seachLoginList() {

		System.out.println("seachLoginList");
		System.out.println("login:"+this.getLogin().getTestname());
		loginList = loginService.searchLoginList();

		return new ForwardResolution(View_TEST);

	}

	
	public Resolution  insertLogin()
	
	{
		System.out.print("insert");
		loginService.insertLogin(login);
		loginList =loginService.searchLoginList();
		
		return new ForwardResolution(VIEW_LIST);
		
	}
	
	
	public Resolution  updateLogin() 
	{
		System.out.println("update");
		loginService.updateLogin(login);
		loginList =loginService.searchLoginList();
		
		return new ForwardResolution(VIEW_LIST);
		
	}
	
	
	
	 public Resolution defaultForward()
	 {
		 
		 return new ForwardResolution(VIEW_INDEX);
		 
	 }
	public List<Login> getLoginList() {
		return loginList;
	}

	public void setLoginList(List<Login> loginList) {
		this.loginList = loginList;
	}



}
